{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <h2>搜索结果: "{{ query }}"</h2>
        <form action="{{ url_for('main.search') }}" method="get" class="mb-4">
            <div class="input-group">
                <input type="text" class="form-control" name="q" value="{{ query }}" placeholder="搜索...">
                <button class="btn btn-primary" type="submit">搜索</button>
            </div>
        </form>
    </div>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">成员 ({{ results.users|length }})</h5>
            </div>
            <div class="card-body">
                {% if results.users %}
                <div class="list-group">
                    {% for user in results.users %}
                    <a href="{{ url_for('users.profile', id=user.id) }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1">{{ user.name }}</h5>
                            <small>{{ user.role }}</small>
                        </div>
                        <small>
                            {% for skill in user.skills %}
                            <span class="badge bg-secondary">{{ skill.name }}</span>
                            {% endfor %}
                        </small>
                    </a>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">没有找到匹配的成员</p>
                {% endif %}
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">文章 ({{ results.articles|length }})</h5>
            </div>
            <div class="card-body">
                {% if results.articles %}
                <div class="list-group">
                    {% for article in results.articles %}
                    <a href="{{ url_for('articles.view', id=article.id) }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1">{{ article.title }}</h5>
                            <small>{{ article.created_at.strftime('%Y-%m-%d') }}</small>
                        </div>
                        <p class="mb-1">作者: {{ article.author.name }}</p>
                        <small>
                            {% for skill in article.skills %}
                            <span class="badge bg-secondary">{{ skill.name }}</span>
                            {% endfor %}
                        </small>
                    </a>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">没有找到匹配的文章</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}